package cn.teawooo.log;

import org.apache.log4j.Logger;

/**
 * 功能描述：
 * @author teawooo <long1795@gmail.com>
 * @time 2013年8月23日 下午4:41:51
 */
public class LoggerFactory {

    public static LocalizationLogger getLogger(Class<?> clazz) {
        return getLogger(clazz.getName());
    }

    public static LocalizationLogger getLogger(String name) {
        LocalizationLogger ls = new LocalizationLoggerWithLog4j(name);
        return ls;
    }

    private static class LocalizationLoggerWithLog4j implements LocalizationLogger {

        private Logger logger;

        public LocalizationLoggerWithLog4j(String name) {
            logger = Logger.getLogger(name);
        }

        @Override
        public void info(String msg, Object... args) {
            logger.info(MessageFormatter.format(msg, args));
        }

        @Override
        public void debug(String msg, Object... args) {
            logger.info(MessageFormatter.format(msg, args));
        }

        @Override
        public void warn(String msg, Object... args) {
            logger.warn(MessageFormatter.format(msg, args));
        }

        @Override
        public void error(Throwable e, String msg, Object... args) {
            logger.error(MessageFormatter.format(msg, args), e);
        }
    }
}
